const Router = require('koa-router')
const get_together = new Router()
//！拿到前端的数据
//数据库连接池
const pg = require('pg');
let psql = new pg.Pool({
  database: 'running',
  user: 'run',
  port: 5432,
  host: '82.157.94.115',
  password: 'z12345678',
  max: 2
})

get_together.get('/get_together', async ctx => {
  let searchContentPostgresql = `select * from together`;
  let content = await psql.query(searchContentPostgresql);
  if (content.rowCount > 0) {
    var togetherObj=[];
    for (var i = 0; i < content.rowCount; i++) {
      var obj = {
        activityname: content.rows[i].activityname,
        location: content.rows[i]. location,
        effectivetime: content.rows[i].effectivetime,
        peoplenum: content.rows[i].peoplenum,
        content: content.rows[i].content,
        realname:content.rows[i].realname,
        contactvalue:content.rows[i].contactvalue
      }
      
      togetherObj.push(obj);
    }

    ctx.body = {
      togetherObj
    };
  }


})

module.exports = get_together